//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package xyz.yuzegod.megawalls.game.stage;

import org.bukkit.Material;
import org.bukkit.block.Furnace;
import org.bukkit.scheduler.BukkitRunnable;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.ClassesManager;
import xyz.yuzegod.megawalls.game.Game;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.game.GameTeam;
import xyz.yuzegod.megawalls.game.GameType;

import java.util.Iterator;

public class ProtectStage extends GameStage {
    public ProtectStage() {
        super("距离开门还有", 15, 10, 0);
    }

    public void excute(final Game game) {
        Iterator var2 = game.getTeams().iterator();

        while(var2.hasNext()) {
            GameTeam gameTeam = (GameTeam)var2.next();
            gameTeam.getReserveWall().falldown();
        }

        game.broadcastMessage("§c§l做好防御准备！");
        var2 = MegaWalls.getIngame().iterator();

        while(var2.hasNext()) {
            GamePlayer gamePlayer = (GamePlayer)var2.next();
            ClassesManager.giveItems(gamePlayer);
        }

        if (game.getGameType() == GameType.NORMAL) {
            (new BukkitRunnable() {
                public void run() {
                    if (game.isWallsFall()) {
                        this.cancel();
                    } else {
                        Iterator var1 = GamePlayer.getOnlinePlayers().iterator();

                        while(var1.hasNext()) {
                            GamePlayer gamePlayer = (GamePlayer)var1.next();
                            gamePlayer.getProtectedBlock().stream().filter((block) -> {
                                return block.getType() == Material.BURNING_FURNACE;
                            }).forEach((block) -> {
                                Furnace furnace = (Furnace)block.getState();
                                furnace.setCookTime((short)(furnace.getCookTime() + 20));
                            });
                        }

                    }
                }
            }).runTaskTimer(MegaWalls.getInstance(), 0L, 20L);
        }

    }

    public void excuteLeftSeconds(Game game, int left) {
        if (left == 10 || left <= 5) {
            game.broadcastMessage("§e你将在§c" + left + "§e秒后获得你的职业套装！");
        }

    }
}
